
<?php 

    include '../loginYanZheng.php';

    weiDengLu();

?>

<!DOCTYPE html>
<html lang="ch">
	<meta charset="utf8">
	<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" type="text/css" href="../layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="index.css">
    <link rel="stylesheet" type="text/css" href="lanrenzhijia.css">
    <link rel="stylesheet" type="text/css" href="loaders.css">
    <style type="">
    	.layui-table th{

    		background-color:rgb(84,146,255);
    		color:#fff;
    		border:1px solid black;
    	}
    </style>
<head>
	<title>客资意向分析</title>
</head>
<body>
	
	<div style="height:30px;"></div>
	
	<div class="layui-fluid">
		<div class="layui-row" >
	      <div class="layui-col-md2">
	              <a href="../jiemian.php"><i class="layui-icon layui-icon-left" style="font-size:20px"></i><div class="doc-icon-name">返回</div></a>
	      </div>
	    </div>
	    <hr>
		<div class="layui-row">
			<!-- 表格部分 -->
			<div id="limit">
							

			</div>

			<div class="layui-tab">
			  <ul class="layui-tab-title">
<!-- 			    <li class="layui-this">硅基</li>
			    
			    <li class="layui-this">百应</li> -->

			    <li class="layui-this">过滤室</li>
			  </ul>
			  <div class="layui-tab-content">
<!-- 			    <div class="layui-tab-item layui-show">

						<div style="display: inline-block;margin-bottom:5px;">
							<button class="layui-btn layui-btn-normal"  id="shuaXin" onclick="glob()"><i class="layui-icon layui-icon-refresh-1"></i></button>

						</div>
						<table id="demo" lay-filter="test"></table>
			    </div> -->

<!-- 			    <div class="layui-tab-item" style="position: relative;">

			    		<button class="layui-btn layui-btn-normal" onclick="getBYjson()">获取百应</button>
						
						<div class="layui-fluid">
							<div class="layui-row">
								<div class="layui-col-md5">
									<table  id="demo1" lay-filter="test1" style="float:left;"></table>
								</div>
								<div class="layui-col-md5">
				
									
								</div>
							</div>
						</div>
	
				</div> -->
				<div class="layui-tab-item layui-show" style="position: relative;">
			    		<button class="layui-btn layui-btn-normal" onclick="cs()"><i class="layui-icon layui-icon-refresh-1"></i></button>
						
						<div class="layui-fluid">
							<div class="layui-row">
								<div class="layui-col-md5">
									<table  id="demo2" lay-filter="test2" style="float:left;"></table>
								</div>
							</div>

						</div>
				</div>
			  </div>
			</div>

			
	</div>
	<div>



		
	</div>
	<!-- 对话部分 -->
	<div id="fake" style="max-height: 800px;width:400px;overflow: auto;display: none;position:absolute;left:70%;top:10px;border:2px solid rgb(84,146,255);">
		<div  class="fake" style="float: left; width:100%">
	      <!-- 造假部分 -->
		    <div class="phonehead">
		    	<div id="clos" onclick="closeBox()" ></div>
		    	<span id="copy">复制</span>
		      	<input id="selectTleeInfo" type="text" name="">
		      	
	      	</div>
		  	<div class="chathead">
		        <!-- 对话框头部 -->
			    <div class="line1" style="text-align: left;">
			        <div id="time_Ai"style="height: 100%; float: left; padding: 2px ; margin: 0 8px;">
			           
			        </div>
			    </div>
		        <div id='name_Ai' class="line1" style="text-align: left;">
		          <!--  客户姓名  -->
		          <audio src="" id="audio" controls="controls" style="width:190px;background:#fff;"></audio>
		        </div>
		        <div class="line1" style="text-align: right; margin-right:4px; width:10%;" >
		          <div>

		            <!-- <img id="play_Ai" style='display: none;' src="img/播放.png" width="20px" height="20px" alt=""> -->
		            
		          </div>
	       		 </div>
	      	</div>
	      	<div id="chat_Ai" class="chat">
		        <!-- 对话内容 -->
		        <div class="dialog1">
		          <div class="avatar1"><img src="img/a.jpg" /></div>
		          <div class="word1">
		            通话内容
		          </div>
		        </div>
		        <div class="dialog2">
		          <div class="word2">
		            啦啦啦啦啦啦
		          </div>
		          <div class="avatar2"><img src="img/B.jpg" /></div>
		        </div>
		    </div>
		</div>
	</div>
</body>


</html>

<script src="../layui/layui.all.js"></script>
<script type="text/javascript" src="index.js"></script>

<script type="text/javascript">

var element = layui.element;




</script>


<script type="text/javascript">

	

	function ttPost(callId,pingTai){ //提交


		event.stopPropagation() //阻止事件冒泡

		jsonData={"callId":callId}

		json=JSON.stringify(jsonData)


		$.post(

			'api.php',

			{data:json,type:1},

			function(data,status){

				console.log(data.body)

				var dt=data.body

				var name=dt.name

				var name=name.replace(/\d+|客户|\|/g,"")

	
				$.post(
					'tt/tt.php',
					{
					 'name':dt.name
					,'phone':dt.phone
					,'dizhi':name
					,'file_all':dt.file_all
					,'list':dt.list
					,'pingTai':pingTai
					},
					function(data,status){

						console.log(data)

						var layer=layui.layer;

						alert(data['msg'])


					}
				)

				
			}
		)

		return false
	}

	function selectSubmitCount(){


		$.post('api.php',{type:7},function(data,status){

			

			$('#limit').html('今日提交：'+data['data'])

		}) //获取当日提交客资数量



	}
	
	//页面层-自定义
	function tanBox(){

			var layer=layui.layer

			$('#fake').show(500)

	}

	function closeBox(){

		var layer=layui.layer

			$('#fake').hide(500)

	}



	function pt(callId){  //获取通话详情 核心架构代码

			jsonData={"callId":callId}

			json=JSON.stringify(jsonData)

				$.post(

					'api.php',

					{data:json,type:1},

					function(data,status){

						console.log(data)
						
						setV(data.body,2)

						
					}
				)

	}

	function setV(data,type){  //通话记录显示


		//$('#name_Ai').html(data.name+'<br> 通话时长：'+data.calltime+'<br> 电话：'+data.phone )

		switch(type){

			case 1:

				//console.log(data)

				//$('#time_Ai').html(' 状态：'+data.myend)

				var reg=/\d+|客户|\|/g

				var name=data[1].custName

				name=name.replace(reg,'')

				var day2 = new Date();

				day2.setTime(day2.getTime());

				var s2 = day2.getFullYear()+"/" + (day2.getMonth()+1) + "/" + day2.getDate();

				$('#selectTleeInfo').val(s2+'\t'+data.bssPlanName+'\t\t'+name+'\t'+data.phone)
				
				var duhuaList=data[0]

				var audio_Ai=data[1]['luyin']

				//console.log(audio_Ai)

				//var guanduan_Ai=data.myend

				$('#chat_Ai').html('')

				var AI_chat_html=''

				var file_part=data.file_part

				for(var i=0;i<duhuaList.length;i++){

					console.log(duhuaList[i].speaker)

					if(duhuaList[i].speaker=='AI'){

						AI_chat_html+= '<div class="dialog1"><div class="avatar1"><img src="img/a.jpg" /></div><div class="word1">'+duhuaList[i]['content']+'</div></div>'

					}else if(duhuaList[i].speaker=='ME'){

						AI_chat_html+= '<div class="dialog2"><div class="avatar2"><div class="word2">'+duhuaList[i]['content']+'</div><img src="img/B.jpg" /></div></div>'
					}



					//AI_chat_html+=(duihua_AI+duihua_user)


				}

				$('#chat_Ai').html(AI_chat_html)

				$('#audio').attr('src',audio_Ai)

				$('#play_Ai').attr('src','img/播放.png')


			break;

			case 2:

				$('#time_Ai').html(' 状态：'+data.myend)

				var reg=/\d+|客户|\|/g

				var name=data.name

				name=name.replace(reg,'')

				var day2 = new Date();
				day2.setTime(day2.getTime());
				var s2 = day2.getFullYear()+"/" + (day2.getMonth()+1) + "/" + day2.getDate();

				$('#selectTleeInfo').val(s2+'\t'+data.bssPlanName+'\t\t'+name+'\t'+data.phone)

				
				var duhuaList=data.list

				var audio_Ai=data.file_all

				var guanduan_Ai=data.myend


				$('#chat_Ai').html('')

				var AI_chat_html=''

				var file_part=data.file_part

				var starttime=data.starttime.split(/-|:| /)

				var endtime=data.endtime.split(/-|:| /)

				var strMiao=parseInt(starttime[4])*60+parseInt(starttime[5])

				var endtMiao=parseInt(endtime[4])*60+parseInt(endtime[5])

				var strPlayTime=endtMiao-strMiao

				console.log(endtMiao-strMiao)


				for(var i=0;i<duhuaList.length;i++){

					var ai=duhuaList[i].answer

					var user=duhuaList[i].content

					var data=duhuaList[i].addtime



					if(ai!==null){

						var duihua_AI= '<div class="dialog1"><div class="avatar1"><img src="img/a.jpg" /></div><div class="word1">'+ai+'</div></div>'

					}else{

						var duihua_AI= ''
					}

					if(user!==null){

						
						var partFile=file_part['file_part_'+(i+1)]

						var audio='<div ><img class="audios" src="img/播放.png" alt="" style="width:20px;height:20px"><audio src="'+partFile+'" id="audio"></audio></div>'

						var duihua_user= '<div class="dialog2"><div class="avatar2"><div class="word2">'+user+'</div><img src="img/B.jpg" /></div></div>'

					}else{

						var duihua_user= ''

					}


					AI_chat_html+=(duihua_AI+duihua_user)


				}

				$('#chat_Ai').html(AI_chat_html)

				$('#audio').attr('src',audio_Ai)

				$('#audio')[0].fastSeek(strPlayTime)

				$('#play_Ai').attr('src','img/播放.png') 

			break;

		}

	}

	function ttPost1(tell,name,luyin,pingTai,callId,renwuName){ //提交

		event.stopPropagation() //阻止事件冒泡

		switch(pingTai){

			case 'by':

				var city=name.replace(/客户|\||\d+/g,"")

				event.stopPropagation() //阻止事件冒泡

				$.post(

					'tt/tt.php',
					{
					 'name':name
					,'phone':tell
					,'dizhi':city
					,'file_all':luyin
					,'list':[{'id':'123','phone':tell,'callId':'0','answer':'暂无','content':'暂无','addtime': '2020-07-03 14:43:19'}]
					,'pingTai':pingTai
					,'renwuName':renwuName
					},
					function(data,status){

						console.log(data)

						var layer=layui.layer;

						alert(data['msg'])

					}
				)

			break;
			case 'gj':


				jsonData={"callId":callId}

				json=JSON.stringify(jsonData)

				$.post(

					'api.php',

					{data:json,type:1},

					function(data,status){

						console.log(data.body)

						var dt=data.body

						var name=dt.name

						var name=name.replace(/\d+|客户|\|/g,"")

			
						$.post(
							'tt/tt.php',
							{
							 'name':dt.name
							,'phone':dt.phone
							,'dizhi':name
							,'file_all':dt.file_all
							,'list':dt.list
							,'pingTai':pingTai
							,'renwuName':renwuName
							},
							function(data,status){

								console.log(data)

								var layer=layui.layer;

								alert(data['msg'])


							}
						)

						
					}
				)


			break;
		}

		
	}


	function BY_V(data){

		
		$('#BYduihua').html('');

		var duihua=data

		var str=""

		for(var i=0;i<duihua.length;i++){


			//console.log(duihua[i])

			

			if(duihua[i]['speaker']=="AI"){

				str+="<div style='margin-bottom:10px;float:left;'>"+duihua[i]['speaker']+":"+duihua[i]['content']+"</div><div style='clear:both'></div>"

			}else{

				str+="<div style='margin-bottom:10px;float:right;background:#ccc;'>"+duihua[i]['content']+":"+duihua[i]['speaker']+"</div><div style='clear:both'></div>"

			}

			

			//$("<div>"+duihua[i]['speaker']+":"+duihua[i]['content']+"</div>")



		}

		$('#BYduihua').html(str);


	}


	cs()

	function cs(){

		selectSubmitCount()


		var table=layui.table

		var layer=layui.layer;

		var index=layer.load()

		table.render({

				   elem: '#demo2' //指定原始表格元素选择器（推荐id选择器）
				  ,height: 680 //容器高度
				  ,width:1000
				  ,method:'post'
				  ,url:'api.php'
				  ,where:{type:8}
				  ,cols: [[
				  	 {field: 'pingTai', title: '拨打平台'}
				  	,{field: 'renWuName', title: '任务名称',width:'80'}
				  	,{field: 'callStartTimeF', title: '拨打时间',width:'180'}
				  	,{field: 'phone', title: '电话',width:'180'}
				  	,{field: 'custName', title: '客户',width:'180'}
				  	,{field: 'duration', title: '接听时长',sort:true} 
				  	,{field: 'result', title: '意向等级',sort:true} 
				  	,{field: 'isRead', title: '已读',templet:function(d){if(d.isRead==1){return '已读'}else{return '<span style="color:black">未读</span>'}}}
				  	,{fileld:'',title:'操作',templet:function(d){return '<button class="layui-btn layui-btn-normal layui-btn-xs"  onclick="ttPost1(\''+d.phone+'\',\''+d.custName+'\',\''+d.luyin+'\',\''+d.pingTai+'\',\''+d.callId+'\',\''+d.renWuName+'\')">提交</button>'}}
				  	
				  	]] //设置表头
				  //,limit:dataArr.length
				  ,limit:15
				  ,page:true
				  //,…… //更多参数参考右侧目录：基本参数选项
				  ,done:function(){

				  	layer.close(index)

				  }

			});

			

							//监听行单击事件
			table.on('row(test2)', function(obj,e){

			  obj.update({isRead:1}) //修改当前行数据

			  $.post(   //设置已读
			  	'api.php'
			  	,{type:2,data:obj.data.callId}
			  	,function(status,data){
			  		//console.log(data)
			  })
			  //tanBox()
			 // console.log(obj.data.callId)
			 if(obj.data.pingTai=='by'){
				  $.post(   

				  	'baiying/BY_selectDB.php'
				  	,{type:2,callInstanceId:obj.data.callId}
				  	,function(data,status){
				  	
				  		data=JSON.parse(data)
				  		console.log(data['data']['phoneLogs'])

				  		setV([data['data']['phoneLogs'],obj.data],1)

				  })
				}else{

						console.log(obj.data.callId)

						$('#audioI').attr('src',obj.data.luyin)

						pt(obj.data.callId)

				}

				tanBox()


			});

	}

	
</script>